home *** CD-ROM | disk | FTP | other *** search
- #include "gestalt.h"
- #include "WDEFGlobals.h"
-
- #define mySIG '©NP©'
-
- OSErr GetWDEFGlobals(create, result) Boolean create; WDEFGlobalsHand result;
- { register Ptr work;
-
- asm
- {
- @start
- move.l #mySIG,d0
- dc.w _Gestalt
- ; OSErr in d0
- bne.s @notThere
- move.l result,a1
- move.l a0,(a1)
- bra.s @exit
- @notThere
- tst.b create
- beq.s @exit
- ; create the globals
- lea @funcEnd,work
- lea @funcBeg,a0
- suba.l a0,work ; size of gestalt function
- move.l work,d0
- add.l #sizeof(WDEFGlobals),d0 ; add in global space
- _NewPtr CLEAR+SYS
- bne.s @exit ; couldn't get memory
- move.l a0,a1
- lea @funcBeg,a0
- move.l work,d0
- move.l a1,work ; save destination
- _BlockMove ; copy function
- move.l #mySIG,d0
- move.l work,a0
- dc.w _NewGestalt ; allocate
- beq.s @start ; ok
- ; failed, return memory
- move.l work,a0
- move.w d0,work ; save reason for fail
- _DisposPtr
- move.w work,d0 ; restore error
- @exit
- }
-
- return;
-
- /* the gestalt function: pascal OSErr funcBeg(OSType, long *) */
- asm
- {
- @funcBeg:
- movem.l (a7)+,d0/a0/a1 ; d0 = return address, a0 = long *, a1 = selector
- clr.w (a7) ; return noErr
- lea @globals,a1
- exg a1,d0 ; ans -> d0, ret addr -> a1
- move.l d0,(a0)
- jmp (a1)
- @funcEnd:
- @globals:
- ; struct WDEFGlobals added here
- }
- }